package com.cndatacom.teleweb.service.impl;

import com.cndatacom.teleweb.common.PaginationModel;
import com.cndatacom.teleweb.dao.IUserDao;
import com.cndatacom.teleweb.model.User;
import com.cndatacom.teleweb.service.IUserService;

public class UserService implements IUserService {

	private IUserDao userDao;
	
	public IUserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	public User getUser(int userId) {
		return userDao.getUserById(userId);
	}

	public User loginValid(String account, String password) {
		return userDao.getUserByAccountAndPassword(account, password);
	}

	public boolean validateAccount(String account) {
		User user = userDao.getUserByAccount(account);
		if(user != null) {
			return true;
		}
		return false;
	}

	public User addOrEditUser(User user) {
		userDao.saveOrUpateUser(user);
		return user;
	}

	public boolean delUser(User user) {
		userDao.delUser(user);
		return true;
	}

	public PaginationModel getAllUser(int offset, int pageSize) {
		return userDao.getAllUser(offset, pageSize);
	}

}
